package com.recipedb.recipedb.controller;

import com.recipedb.recipedb.entity.RecipeIngredient;
import com.recipedb.recipedb.entity.RecipeIngredientId;
import com.recipedb.recipedb.entity.UserFollow;
import com.recipedb.recipedb.service.RecipeIngredientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/recipeingredient")
public class RecipeIngredientController {

    @Autowired
    private RecipeIngredientService service;

    @PostMapping
    public RecipeIngredient add(@RequestBody RecipeIngredient entity) {
        return service.save(entity);
    }

    @DeleteMapping
    public void delete(@RequestBody RecipeIngredientId id) {
        service.deleteById(id);
    }

    @GetMapping("/single")
    public Optional<RecipeIngredient> get(@RequestBody RecipeIngredientId id) {
        return service.findById(id);
    }

    @GetMapping("/all")
    public List<RecipeIngredient> getAll() {
        return service.findAll();
    }

}
